#include "simple.h"
#include <unistd.h>
#include <pthread.h>
#include "xtracelib.h"

_Thread_local int bsd_call_nr = -1;

static void print_errno(char* buf, uintptr_t rv);
static void print_errno_num(char* buf, uintptr_t rv);
static void print_errno_ptr(char* buf, uintptr_t rv);

// awk '/^[0-9]/ { if ($6 !~ "nosys") { split($6, a, "("); print "[" $1 "] = { \"" a[1] "\", NULL, print_errno }," } }'

static const struct calldef bsd_defs[600] = {
	[1] = { "exit", NULL, print_errno_num },
	[2] = { "fork", NULL, print_errno_num },
	[3] = { "read", NULL, print_errno_num },
	[4] = { "write", NULL, print_errno_num },
	[5] = { "open", NULL, print_errno_num },
	[6] = { "close", NULL, print_errno_num },
	[7] = { "wait4", NULL, print_errno_num },
	[9] = { "link", NULL, print_errno_num },
	[10] = { "unlink", NULL, print_errno_num },
	[12] = { "chdir", NULL, print_errno_num },
	[13] = { "fchdir", NULL, print_errno_num },
	[14] = { "mknod", NULL, print_errno_num },
	[15] = { "chmod", NULL, print_errno_num },
	[16] = { "chown", NULL, print_errno_num },
	[18] = { "getfsstat", NULL, print_errno_num },
	[20] = { "getpid", NULL, print_errno_num },
	[23] = { "setuid", NULL, print_errno_num },
	[24] = { "getuid", NULL, print_errno_num },
	[25] = { "geteuid", NULL, print_errno_num },
	[26] = { "ptrace", NULL, print_errno_num },
	[27] = { "recvmsg", NULL, print_errno_num },
	[28] = { "sendmsg", NULL, print_errno_num },
	[29] = { "recvfrom", NULL, print_errno_num },
	[30] = { "accept", NULL, print_errno_num },
	[31] = { "getpeername", NULL, print_errno_num },
	[32] = { "getsockname", NULL, print_errno_num },
	[33] = { "access", NULL, print_errno_num },
	[34] = { "chflags", NULL, print_errno_num },
	[35] = { "fchflags", NULL, print_errno_num },
	[36] = { "sync", NULL, print_errno_num },
	[37] = { "kill", NULL, print_errno_num },
	[39] = { "getppid", NULL, print_errno_num },
	[41] = { "dup", NULL, print_errno_num },
	[42] = { "pipe", NULL, print_errno_num },
	[43] = { "getegid", NULL, print_errno_num },
	[46] = { "sigaction", NULL, print_errno_num },
	[47] = { "getgid", NULL, print_errno_num },
	[48] = { "sigprocmask", NULL, print_errno_num },
	[49] = { "getlogin", NULL, print_errno_num },
	[50] = { "setlogin", NULL, print_errno_num },
	[51] = { "acct", NULL, print_errno_num },
	[52] = { "sigpending", NULL, print_errno_num },
	[53] = { "sigaltstack", NULL, print_errno_num },
	[54] = { "ioctl", NULL, print_errno_num },
	[55] = { "reboot", NULL, print_errno_num },
	[56] = { "revoke", NULL, print_errno_num },
	[57] = { "symlink", NULL, print_errno_num },
	[58] = { "readlink", NULL, print_errno_num },
	[59] = { "execve", NULL, print_errno_num },
	[60] = { "umask", NULL, print_errno_num },
	[61] = { "chroot", NULL, print_errno_num },
	[65] = { "msync", NULL, print_errno_num },
	[66] = { "vfork", NULL, print_errno_num },
	[73] = { "munmap", NULL, print_errno_num },
	[74] = { "mprotect", NULL, print_errno_num },
	[75] = { "madvise", NULL, print_errno_num },
	[78] = { "mincore", NULL, print_errno_num },
	[79] = { "getgroups", NULL, print_errno_num },
	[80] = { "setgroups", NULL, print_errno_num },
	[81] = { "getpgrp", NULL, print_errno_num },
	[82] = { "setpgid", NULL, print_errno_num },
	[83] = { "setitimer", NULL, print_errno_num },
	[85] = { "swapon", NULL, print_errno_num },
	[86] = { "getitimer", NULL, print_errno_num },
	[89] = { "getdtablesize", NULL, print_errno_num },
	[90] = { "dup2", NULL, print_errno_num },
	[92] = { "fcntl", NULL, print_errno_num },
	[93] = { "select", NULL, print_errno_num },
	[95] = { "fsync", NULL, print_errno_num },
	[96] = { "setpriority", NULL, print_errno_num },
	[97] = { "socket", NULL, print_errno_num },
	[98] = { "connect", NULL, print_errno_num },
	[100] = { "getpriority", NULL, print_errno_num },
	[104] = { "bind", NULL, print_errno_num },
	[105] = { "setsockopt", NULL, print_errno_num },
	[106] = { "listen", NULL, print_errno_num },
	[111] = { "sigsuspend", NULL, print_errno_num },
	[116] = { "gettimeofday", NULL, print_errno_num },
	[117] = { "getrusage", NULL, print_errno_num },
	[118] = { "getsockopt", NULL, print_errno_num },
	[120] = { "readv", NULL, print_errno_num },
	[121] = { "writev", NULL, print_errno_num },
	[122] = { "settimeofday", NULL, print_errno_num },
	[123] = { "fchown", NULL, print_errno_num },
	[124] = { "fchmod", NULL, print_errno_num },
	[126] = { "setreuid", NULL, print_errno_num },
	[127] = { "setregid", NULL, print_errno_num },
	[128] = { "rename", NULL, print_errno_num },
	[131] = { "flock", NULL, print_errno_num },
	[132] = { "mkfifo", NULL, print_errno_num },
	[133] = { "sendto", NULL, print_errno_num },
	[134] = { "shutdown", NULL, print_errno_num },
	[135] = { "socketpair", NULL, print_errno_num },
	[136] = { "mkdir", NULL, print_errno_num },
	[137] = { "rmdir", NULL, print_errno_num },
	[138] = { "utimes", NULL, print_errno_num },
	[139] = { "futimes", NULL, print_errno_num },
	[140] = { "adjtime", NULL, print_errno_num },
	[142] = { "gethostuuid", NULL, print_errno_num },
	[147] = { "setsid", NULL, print_errno_num },
	[151] = { "getpgid", NULL, print_errno_num },
	[152] = { "setprivexec", NULL, print_errno_num },
	[153] = { "pread", NULL, print_errno_num },
	[154] = { "pwrite", NULL, print_errno_num },
	[155] = { "nfssvc", NULL, print_errno_num },
	[157] = { "statfs", NULL, print_errno_num },
	[158] = { "fstatfs", NULL, print_errno_num },
	[159] = { "unmount", NULL, print_errno_num },
	[161] = { "getfh", NULL, print_errno_num },
	[165] = { "quotactl", NULL, print_errno_num },
	[167] = { "mount", NULL, print_errno_num },
	[169] = { "csops", NULL, print_errno_num },
	[170] = { "csops_audittoken", NULL, print_errno_num },
	[173] = { "waitid", NULL, print_errno_num },
	[177] = { "kdebug_typefilter", NULL, print_errno_num },
	[178] = { "kdebug_trace_string", NULL, print_errno_num },
	[179] = { "kdebug_trace64", NULL, print_errno_num },
	[180] = { "kdebug_trace", NULL, print_errno_num },
	[181] = { "setgid", NULL, print_errno_num },
	[182] = { "setegid", NULL, print_errno_num },
	[183] = { "seteuid", NULL, print_errno_num },
	[184] = { "sigreturn", NULL, print_errno_num },
	[187] = { "fdatasync", NULL, print_errno_num },
	[188] = { "stat", NULL, print_errno_num },
	[189] = { "fstat", NULL, print_errno_num },
	[190] = { "lstat", NULL, print_errno_num },
	[191] = { "pathconf", NULL, print_errno_num },
	[192] = { "fpathconf", NULL, print_errno_num },
	[194] = { "getrlimit", NULL, print_errno_num },
	[195] = { "setrlimit", NULL, print_errno_num },
	[196] = { "getdirentries", NULL, print_errno_num },
	[197] = { "mmap", NULL, print_errno_ptr },
	[199] = { "lseek", NULL, print_errno_num },
	[200] = { "truncate", NULL, print_errno_num },
	[201] = { "ftruncate", NULL, print_errno_num },
	[202] = { "sysctl", NULL, print_errno_num },
	[203] = { "mlock", NULL, print_errno_num },
	[204] = { "munlock", NULL, print_errno_num },
	[205] = { "undelete", NULL, print_errno_num },
	[216] = { "open_dprotected_np", NULL, print_errno_num },
	[220] = { "getattrlist", NULL, print_errno_num },
	[221] = { "setattrlist", NULL, print_errno_num },
	[222] = { "getdirentriesattr", NULL, print_errno_num },
	[223] = { "exchangedata", NULL, print_errno_num },
	[225] = { "searchfs", NULL, print_errno_num },
	[226] = { "delete", NULL, print_errno_num },
	[227] = { "copyfile", NULL, print_errno_num },
	[228] = { "fgetattrlist", NULL, print_errno_num },
	[229] = { "fsetattrlist", NULL, print_errno_num },
	[230] = { "poll", NULL, print_errno_num },
	[231] = { "watchevent", NULL, print_errno_num },
	[232] = { "waitevent", NULL, print_errno_num },
	[233] = { "modwatch", NULL, print_errno_num },
	[234] = { "getxattr", NULL, print_errno_num },
	[235] = { "fgetxattr", NULL, print_errno_num },
	[236] = { "setxattr", NULL, print_errno_num },
	[237] = { "fsetxattr", NULL, print_errno_num },
	[238] = { "removexattr", NULL, print_errno_num },
	[239] = { "fremovexattr", NULL, print_errno_num },
	[240] = { "listxattr", NULL, print_errno_num },
	[241] = { "flistxattr", NULL, print_errno_num },
	[242] = { "fsctl", NULL, print_errno_num },
	[243] = { "initgroups", NULL, print_errno_num },
	[244] = { "posix_spawn", NULL, print_errno_num },
	[245] = { "ffsctl", NULL, print_errno_num },
	[247] = { "nfsclnt", NULL, print_errno_num },
	[248] = { "fhopen", NULL, print_errno_num },
	[250] = { "minherit", NULL, print_errno_num },
	[251] = { "semsys", NULL, print_errno_num },
	[252] = { "msgsys", NULL, print_errno_num },
	[253] = { "shmsys", NULL, print_errno_num },
	[254] = { "semctl", NULL, print_errno_num },
	[255] = { "semget", NULL, print_errno_num },
	[256] = { "semop", NULL, print_errno_num },
	[258] = { "msgctl", NULL, print_errno_num },
	[259] = { "msgget", NULL, print_errno_num },
	[260] = { "msgsnd", NULL, print_errno_num },
	[261] = { "msgrcv", NULL, print_errno_num },
	[262] = { "shmat", NULL, print_errno_num },
	[263] = { "shmctl", NULL, print_errno_num },
	[264] = { "shmdt", NULL, print_errno_num },
	[265] = { "shmget", NULL, print_errno_num },
	[266] = { "shm_open", NULL, print_errno_num },
	[267] = { "shm_unlink", NULL, print_errno_num },
	[268] = { "sem_open", NULL, print_errno_num },
	[269] = { "sem_close", NULL, print_errno_num },
	[270] = { "sem_unlink", NULL, print_errno_num },
	[271] = { "sem_wait", NULL, print_errno_num },
	[272] = { "sem_trywait", NULL, print_errno_num },
	[273] = { "sem_post", NULL, print_errno_num },
	[274] = { "sysctlbyname", NULL, print_errno_num },
	[277] = { "open_extended", NULL, print_errno_num },
	[278] = { "umask_extended", NULL, print_errno_num },
	[279] = { "stat_extended", NULL, print_errno_num },
	[280] = { "lstat_extended", NULL, print_errno_num },
	[281] = { "fstat_extended", NULL, print_errno_num },
	[282] = { "chmod_extended", NULL, print_errno_num },
	[283] = { "fchmod_extended", NULL, print_errno_num },
	[284] = { "access_extended", NULL, print_errno_num },
	[285] = { "settid", NULL, print_errno_num },
	[286] = { "gettid", NULL, print_errno_num },
	[287] = { "setsgroups", NULL, print_errno_num },
	[288] = { "getsgroups", NULL, print_errno_num },
	[289] = { "setwgroups", NULL, print_errno_num },
	[290] = { "getwgroups", NULL, print_errno_num },
	[291] = { "mkfifo_extended", NULL, print_errno_num },
	[292] = { "mkdir_extended", NULL, print_errno_num },
	[293] = { "identitysvc", NULL, print_errno_num },
	[294] = { "shared_region_check_np", NULL, print_errno_num },
	[296] = { "vm_pressure_monitor", NULL, print_errno_num },
	[297] = { "psynch_rw_longrdlock", NULL, print_errno_num },
	[298] = { "psynch_rw_yieldwrlock", NULL, print_errno_num },
	[299] = { "psynch_rw_downgrade", NULL, print_errno_num },
	[300] = { "psynch_rw_upgrade", NULL, print_errno_num },
	[301] = { "psynch_mutexwait", NULL, print_errno_num },
	[302] = { "psynch_mutexdrop", NULL, print_errno_num },
	[303] = { "psynch_cvbroad", NULL, print_errno_num },
	[304] = { "psynch_cvsignal", NULL, print_errno_num },
	[305] = { "psynch_cvwait", NULL, print_errno_num },
	[306] = { "psynch_rw_rdlock", NULL, print_errno_num },
	[307] = { "psynch_rw_wrlock", NULL, print_errno_num },
	[308] = { "psynch_rw_unlock", NULL, print_errno_num },
	[309] = { "psynch_rw_unlock2", NULL, print_errno_num },
	[310] = { "getsid", NULL, print_errno_num },
	[311] = { "settid_with_pid", NULL, print_errno_num },
	[312] = { "psynch_cvclrprepost", NULL, print_errno_num },
	[313] = { "aio_fsync", NULL, print_errno_num },
	[314] = { "aio_return", NULL, print_errno_num },
	[315] = { "aio_suspend", NULL, print_errno_num },
	[316] = { "aio_cancel", NULL, print_errno_num },
	[317] = { "aio_error", NULL, print_errno_num },
	[318] = { "aio_read", NULL, print_errno_num },
	[319] = { "aio_write", NULL, print_errno_num },
	[320] = { "lio_listio", NULL, print_errno_num },
	[322] = { "iopolicysys", NULL, print_errno_num },
	[323] = { "process_policy", NULL, print_errno_num },
	[324] = { "mlockall", NULL, print_errno_num },
	[325] = { "munlockall", NULL, print_errno_num },
	[327] = { "issetugid", NULL, print_errno_num },
	[328] = { "__pthread_kill", NULL, print_errno_num },
	[329] = { "__pthread_sigmask", NULL, print_errno_num },
	[330] = { "__sigwait", NULL, print_errno_num },
	[331] = { "__disable_threadsignal", NULL, print_errno_num },
	[332] = { "__pthread_markcancel", NULL, print_errno_num },
	[333] = { "__pthread_canceled", NULL, print_errno_num },
	[334] = { "__semwait_signal", NULL, print_errno_num },
	[336] = { "proc_info", NULL, print_errno_num },
	[337] = { "sendfile", NULL, print_errno_num },
	[338] = { "stat64", NULL, print_errno_num },
	[339] = { "fstat64", NULL, print_errno_num },
	[340] = { "lstat64", NULL, print_errno_num },
	[341] = { "stat64_extended", NULL, print_errno_num },
	[342] = { "lstat64_extended", NULL, print_errno_num },
	[343] = { "fstat64_extended", NULL, print_errno_num },
	[344] = { "getdirentries64", NULL, print_errno_num },
	[345] = { "statfs64", NULL, print_errno_num },
	[346] = { "fstatfs64", NULL, print_errno_num },
	[347] = { "getfsstat64", NULL, print_errno_num },
	[348] = { "__pthread_chdir", NULL, print_errno_num },
	[349] = { "__pthread_fchdir", NULL, print_errno_num },
	[350] = { "audit", NULL, print_errno_num },
	[351] = { "auditon", NULL, print_errno_num },
	[353] = { "getauid", NULL, print_errno_num },
	[354] = { "setauid", NULL, print_errno_num },
	[357] = { "getaudit_addr", NULL, print_errno_num },
	[358] = { "setaudit_addr", NULL, print_errno_num },
	[359] = { "auditctl", NULL, print_errno_num },
	[360] = { "bsdthread_create", NULL, print_errno_num },
	[361] = { "bsdthread_terminate", NULL, print_errno_num },
	[362] = { "kqueue", NULL, print_errno_num },
	[363] = { "kevent", NULL, print_errno_num },
	[364] = { "lchown", NULL, print_errno_num },
	[366] = { "bsdthread_register", NULL, print_errno_num },
	[367] = { "workq_open", NULL, print_errno_num },
	[368] = { "workq_kernreturn", NULL, print_errno_num },
	[369] = { "kevent64", NULL, print_errno_num },
	[370] = { "__old_semwait_signal", NULL, print_errno_num },
	[371] = { "__old_semwait_signal_nocancel", NULL, print_errno_num },
	[372] = { "thread_selfid", NULL, print_errno_num },
	[373] = { "ledger", NULL, print_errno_num },
	[374] = { "kevent_qos", NULL, print_errno_num },
	[380] = { "__mac_execve", NULL, print_errno_num },
	[381] = { "__mac_syscall", NULL, print_errno_num },
	[382] = { "__mac_get_file", NULL, print_errno_num },
	[383] = { "__mac_set_file", NULL, print_errno_num },
	[384] = { "__mac_get_link", NULL, print_errno_num },
	[385] = { "__mac_set_link", NULL, print_errno_num },
	[386] = { "__mac_get_proc", NULL, print_errno_num },
	[387] = { "__mac_set_proc", NULL, print_errno_num },
	[388] = { "__mac_get_fd", NULL, print_errno_num },
	[389] = { "__mac_set_fd", NULL, print_errno_num },
	[390] = { "__mac_get_pid", NULL, print_errno_num },
	[394] = { "pselect", NULL, print_errno_num },
	[395] = { "pselect_nocancel", NULL, print_errno_num },
	[396] = { "read_nocancel", NULL, print_errno_num },
	[397] = { "write_nocancel", NULL, print_errno_num },
	[398] = { "open_nocancel", NULL, print_errno_num },
	[399] = { "close_nocancel", NULL, print_errno_num },
	[400] = { "wait4_nocancel", NULL, print_errno_num },
	[401] = { "recvmsg_nocancel", NULL, print_errno_num },
	[402] = { "sendmsg_nocancel", NULL, print_errno_num },
	[403] = { "recvfrom_nocancel", NULL, print_errno_num },
	[404] = { "accept_nocancel", NULL, print_errno_num },
	[405] = { "msync_nocancel", NULL, print_errno_num },
	[406] = { "fcntl_nocancel", NULL, print_errno_num },
	[407] = { "select_nocancel", NULL, print_errno_num },
	[408] = { "fsync_nocancel", NULL, print_errno_num },
	[409] = { "connect_nocancel", NULL, print_errno_num },
	[410] = { "sigsuspend_nocancel", NULL, print_errno_num },
	[411] = { "readv_nocancel", NULL, print_errno_num },
	[412] = { "writev_nocancel", NULL, print_errno_num },
	[413] = { "sendto_nocancel", NULL, print_errno_num },
	[414] = { "pread_nocancel", NULL, print_errno_num },
	[415] = { "pwrite_nocancel", NULL, print_errno_num },
	[416] = { "waitid_nocancel", NULL, print_errno_num },
	[417] = { "poll_nocancel", NULL, print_errno_num },
	[418] = { "msgsnd_nocancel", NULL, print_errno_num },
	[419] = { "msgrcv_nocancel", NULL, print_errno_num },
	[420] = { "sem_wait_nocancel", NULL, print_errno_num },
	[421] = { "aio_suspend_nocancel", NULL, print_errno_num },
	[422] = { "__sigwait_nocancel", NULL, print_errno_num },
	[423] = { "__semwait_signal_nocancel", NULL, print_errno_num },
	[424] = { "__mac_mount", NULL, print_errno_num },
	[425] = { "__mac_get_mount", NULL, print_errno_num },
	[426] = { "__mac_getfsstat", NULL, print_errno_num },
	[427] = { "fsgetpath", NULL, print_errno_num },
	[428] = { "audit_session_self", NULL, print_errno_num },
	[429] = { "audit_session_join", NULL, print_errno_num },
	[430] = { "fileport_makeport", NULL, print_errno_num },
	[431] = { "fileport_makefd", NULL, print_errno_num },
	[432] = { "audit_session_port", NULL, print_errno_num },
	[433] = { "pid_suspend", NULL, print_errno_num },
	[434] = { "pid_resume", NULL, print_errno_num },
	[438] = { "shared_region_map_and_slide_np", NULL, print_errno_num },
	[439] = { "kas_info", NULL, print_errno_num },
	[440] = { "memorystatus_control", NULL, print_errno_num },
	[441] = { "guarded_open_np", NULL, print_errno_num },
	[442] = { "guarded_close_np", NULL, print_errno_num },
	[443] = { "guarded_kqueue_np", NULL, print_errno_num },
	[444] = { "change_fdguard_np", NULL, print_errno_num },
	[445] = { "usrctl", NULL, print_errno_num },
	[446] = { "proc_rlimit_control", NULL, print_errno_num },
	[447] = { "connectx", NULL, print_errno_num },
	[448] = { "disconnectx", NULL, print_errno_num },
	[449] = { "peeloff", NULL, print_errno_num },
	[450] = { "socket_delegate", NULL, print_errno_num },
	[451] = { "telemetry", NULL, print_errno_num },
	[452] = { "proc_uuid_policy", NULL, print_errno_num },
	[453] = { "memorystatus_get_level", NULL, print_errno_num },
	[454] = { "system_override", NULL, print_errno_num },
	[455] = { "vfs_purge", NULL, print_errno_num },
	[456] = { "sfi_ctl", NULL, print_errno_num },
	[457] = { "sfi_pidctl", NULL, print_errno_num },
	[458] = { "coalition", NULL, print_errno_num },
	[459] = { "coalition_info", NULL, print_errno_num },
	[460] = { "necp_match_policy", NULL, print_errno_num },
	[461] = { "getattrlistbulk", NULL, print_errno_num },
	[462] = { "clonefileat", NULL, print_errno_num },
	[463] = { "openat", NULL, print_errno_num },
	[464] = { "openat_nocancel", NULL, print_errno_num },
	[465] = { "renameat", NULL, print_errno_num },
	[466] = { "faccessat", NULL, print_errno_num },
	[467] = { "fchmodat", NULL, print_errno_num },
	[468] = { "fchownat", NULL, print_errno_num },
	[469] = { "fstatat", NULL, print_errno_num },
	[470] = { "fstatat64", NULL, print_errno_num },
	[471] = { "linkat", NULL, print_errno_num },
	[472] = { "unlinkat", NULL, print_errno_num },
	[473] = { "readlinkat", NULL, print_errno_num },
	[474] = { "symlinkat", NULL, print_errno_num },
	[475] = { "mkdirat", NULL, print_errno_num },
	[476] = { "getattrlistat", NULL, print_errno_num },
	[477] = { "proc_trace_log", NULL, print_errno_num },
	[478] = { "bsdthread_ctl", NULL, print_errno_num },
	[479] = { "openbyid_np", NULL, print_errno_num },
	[480] = { "recvmsg_x", NULL, print_errno_num },
	[481] = { "sendmsg_x", NULL, print_errno_num },
	[482] = { "thread_selfusage", NULL, print_errno_num },
	[483] = { "csrctl", NULL, print_errno_num },
	[484] = { "guarded_open_dprotected_np", NULL, print_errno_num },
	[485] = { "guarded_write_np", NULL, print_errno_num },
	[486] = { "guarded_pwrite_np", NULL, print_errno_num },
	[487] = { "guarded_writev_np", NULL, print_errno_num },
	[488] = { "renameatx_np", NULL, print_errno_num },
	[489] = { "mremap_encrypted", NULL, print_errno_num },
	[490] = { "netagent_trigger", NULL, print_errno_num },
	[491] = { "stack_snapshot_with_config", NULL, print_errno_num },
	[492] = { "microstackshot", NULL, print_errno_num },
	[493] = { "grab_pgo_data", NULL, print_errno_num },
	[494] = { "persona", NULL, print_errno_num },
	[499] = { "work_interval_ctl", NULL, print_errno_num },
	[500] = { "getentropy", NULL, print_errno_num },
	[501] = { "necp_open", NULL, print_errno_num },
	[502] = { "necp_client_action", NULL, print_errno_num },
	[515] = { "ulock_wait", NULL, print_errno_num },
	[516] = { "ulock_wake", NULL, print_errno_num },
	[517] = { "fclonefileat", NULL, print_errno_num },
	[518] = { "fs_snapshot", NULL, print_errno_num },
	[520] = { "terminate_with_payload", NULL, print_errno_num },
	[521] = { "abort_with_payload", NULL, print_errno_num },
};

extern "C"
void darling_bsd_syscall_entry_print(int nr, void* args[])
{
	bsd_call_nr = nr;
	handle_generic_entry(bsd_defs, "bsd", bsd_call_nr, args);
}

extern "C"
void darling_bsd_syscall_exit_print(uintptr_t retval)
{
	handle_generic_exit(bsd_defs, "bsd", bsd_call_nr, retval);
	bsd_call_nr = -1;
}

const char* error_strings[128] = {
	[1] = "EPERM",
	[2] = "ENOENT",
	[3] = "ESRCH",
	[4] = "EINTR",
	[5] = "EIO",
	[6] = "ENXIO",
	[7] = "E2BIG",
	[8] = "ENOEXEC",
	[9] = "EBADF",
	[10] = "ECHILD",
	[11] = "EDEADLK",
	[12] = "ENOMEM",
	[13] = "EACCES",
	[14] = "EFAULT",
	[15] = "ENOTBLK",
	[16] = "EBUSY",
	[17] = "EEXIST",
	[18] = "EXDEV",
	[19] = "ENODEV",
	[20] = "ENOTDIR",
	[21] = "EISDIR",
	[22] = "EINVAL",
	[23] = "ENFILE",
	[24] = "EMFILE",
	[25] = "ENOTTY",
	[26] = "ETXTBSY",
	[27] = "EFBIG",
	[28] = "ENOSPC",
	[29] = "ESPIPE",
	[30] = "EROFS",
	[31] = "EMLINK",
	[32] = "EPIPE",
	[33] = "EDOM",
	[34] = "ERANGE",
	[35] = "EAGAIN",
	[36] = "EINPROGRESS",
	[37] = "EALREADY",
	[38] = "ENOTSOCK",
	[39] = "EDESTADDRREQ",
	[40] = "EMSGSIZE",
	[41] = "EPROTOTYPE",
	[42] = "ENOPROTOOPT",
	[43] = "EPROTONOSUPPORT",
	[44] = "ESOCKTNOSUPPORT",
	[45] = "ENOTSUP",
	[46] = "EPFNOSUPPORT",
	[47] = "EAFNOSUPPORT",
	[48] = "EADDRINUSE",
	[49] = "EADDRNOTAVAIL",
	[50] = "ENETDOWN",
	[51] = "ENETUNREACH",
	[52] = "ENETRESET",
	[53] = "ECONNABORTED",
	[54] = "ECONNRESET",
	[55] = "ENOBUFS",
	[56] = "EISCONN",
	[57] = "ENOTCONN",
	[58] = "ESHUTDOWN",
	[59] = "ETOOMANYREFS",
	[60] = "ETIMEDOUT",
	[61] = "ECONNREFUSED",
	[62] = "ELOOP",
	[63] = "ENAMETOOLONG",
	[64] = "EHOSTDOWN",
	[65] = "EHOSTUNREACH",
	[66] = "ENOTEMPTY",
	[67] = "EPROCLIM",
	[68] = "EUSERS",
	[69] = "EDQUOT",
	[70] = "ESTALE",
	[71] = "EREMOTE",
	[72] = "EBADRPC",
	[73] = "ERPCMISMATCH",
	[74] = "EPROGUNAVAIL",
	[75] = "EPROGMISMATCH",
	[76] = "EPROCUNAVAIL",
	[77] = "ENOLCK",
	[78] = "ENOSYS",
	[79] = "EFTYPE",
	[80] = "EAUTH",
	[81] = "ENEEDAUTH",
	[82] = "EPWROFF",
	[83] = "EDEVERR",
	[84] = "EOVERFLOW",
	[85] = "EBADEXEC",
	[86] = "EBADARCH",
	[87] = "ESHLIBVERS",
	[88] = "EBADMACHO",
	[89] = "ECANCELED",
	[90] = "EIDRM",
	[91] = "ENOMSG",
	[92] = "EILSEQ",
	[93] = "ENOATTR",
	[94] = "EBADMSG",
	[95] = "EMULTIHOP",
	[96] = "ENODATA",
	[97] = "ENOLINK",
	[98] = "ENOSR",
	[99] = "ENOSTR",
	[100] = "EPROTO",
	[101] = "ETIME",
	[102] = "EOPNOTSUPP",
	[103] = "ENOPOLICY",
	[104] = "ENOTRECOVERABLE",
	[105] = "EOWNERDEAD",
	[106] = "EQFULL",
};

static void print_errno_num(char* buf, uintptr_t rv)
{
	intptr_t v = (intptr_t)rv;
	if (v >= 0 || v < -4095)
	{
		__simple_sprintf(buf, "%d", rv);
	}
	else
		print_errno(buf, rv);
}

static void print_errno_ptr(char* buf, uintptr_t rv)
{
	intptr_t v = (intptr_t)rv;
	if (v >= 0 || v < -4095)
	{
		__simple_sprintf(buf, "%p", rv);
	}
	else
		print_errno(buf, rv);
}

static void print_errno(char* buf, uintptr_t rv)
{
	const char* error = NULL;
	intptr_t v = (intptr_t)rv;
	if (-v < 128)
		error = error_strings[-v];
	if (error != NULL)
		__simple_sprintf(buf, "%s", error);
	else
		__simple_sprintf(buf, "%d", v);
}

